<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-09-26
 * Time: 14:06
 */

namespace App\Http\Controllers\Mobile;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Validator\UserVali;
use App\Model\Backstage\User;
use App\Model\Mobile\MobilePlan;
use App\Tool\Error;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;
use Validator;

class LoginController extends Controller
{
    public function appLogin(Request $request)
    {
        $params = $request->all();
        $vali = UserVali::loginValidate($params);
        if(!$vali){
            return $this->error(Error::PARAM_MISSING);
        }
        $res = MobilePlan::appLogin($params);
        if ($res === -4) {
            //账号不存在
            return $this->error(Error::USERNAME_NULL);
        }
        if ($res === -5) {
            //账号被禁用
            return $this->error(Error::ACCOUNT_DISABLE);
        }
        if ($res === -6) {
            //账号被删除
            return $this->error(Error::ACCOUNT_DEL);
        }
        if ($res === -1) {
            //公司还在审核中不能登录
            return $this->error(Error::AUDIT);
        }
        if ($res === -2) {
            //公司账号到期没有续费无法登录
            return $this->error(Error::NO_RENEWAL);
        }
        if ($res === -3) {
            //未知错误 请联系管理员
            return $this->error(Error::PLEASE_CONTACT_ADMIN);
        }
        if ($res === -7) {
            //该账号无权限登录
            return $this->error(Error::APP_NO_LOGIN);
        }
        if($res){
            return $this->success('ok',$res);
        }else{
            return $this->error(Error::PASSWORD_ERROR);
        }

    }
}